﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NG;
using Excel = Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
using System.IO;

namespace NGDesign
{
    public partial class Form1 : Form
    {

        public Panel user_pnl;
        public Label connected_user;
        public Label connected_as;
        public Label proj_name;
        public Label current_proj;
        public DataTable ksfProjectTable;
        public DataTable rolesTable;
        public Interview current_interview;

        public Form1()
        {
            InitializeComponent();
            //this.Height = Screen.PrimaryScreen.WorkingArea.Height;
            EditComponent();
        }
        // 
        // tabPage1
        // 
        private void tabPage1_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 1;
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.tab1_link_lbl.Links[tab1_link_lbl.Links.IndexOf(e.Link)].Visited = true;
            System.Diagnostics.Process.Start("http://www.niramgitan.com/");
        }
        // 
        // tabPage2
        // 
        private void help_btn2_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }

        private void tab2_connect_Click(object sender, EventArgs e)
        {

            User user = new User(tab2_user_name_txt.Text, tab2_password_txt.Text, 0);
            IUserHandler IUH = new userHandler();
            if (IUH.login(user))
            {
                this.tabControl1.SelectedIndex = 2;
            }
            else
            {
                MessageBox.Show("שם משתמש או סיסמה שגויים,נסה שנית.");
                tab2_user_name_txt.Clear();
                tab2_password_txt.Clear();
                return;
            }
            connected_user.Tag = user;
            connected_user.Text = user.username;
        }

        private void tab2_cancel_Click(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }
        // 
        // tabPage3
        // 
        private void tab3_open_btn_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 3;
        }

        private void tab3_create_btn_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 4;
        }


        private void help_btn3_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }
        // 
        // tabPage4
        // 
        private void back_to_menu4_Click(object sender, EventArgs e)
        {
            tab4_comboBox1.SelectedIndex = -1;
            tab4_comboBox2.SelectedIndex = -1;
            tab4_comboBox3.SelectedIndex = -1;
            tab4_comboBox4.SelectedIndex = -1;
            tab4_comboBox5.SelectedIndex = -1;
            tab4_comboBox6.SelectedIndex = -1;
            this.tabControl1.SelectedIndex = 2;
            listView1.Clear();

        }


        private void left_btn4_Click(object sender, EventArgs e)
        {

            IProjectHandler IPH = new projectHandler();
            if (tab4_comboBox2.SelectedItem == null)
            {
                MessageBox.Show("נא להכניס תת ענף");
                return;
            }
            if (tab4_comboBox6.SelectedItem == null)
            {
                MessageBox.Show("נא להכניס תת מחלקה");
                return;
            }
            LinkedList<Project> proList = IPH.allProjectsBysDep("project_no", true, (SubDepartment)tab4_comboBox6.SelectedItem, ((SubIndustry)tab4_comboBox2.SelectedItem));
            foreach (Project pro in proList)
            {
                string[] st = new string[4];
                st[0] = pro.ID.ToString();
                st[1] = pro.name;
                st[2] = pro.cname;
                st[3] = pro.oDate.ToString();
                ListViewItem items = new ListViewItem(st);
                items.Tag = pro;
                listView1.Items.Add(items);
            }
        }




        private void help_btn4_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }
        // 
        // tabPage5
        // 
        private void back_to_menu5_Click(object sender, EventArgs e)
        {
            tab5_txt1.Text = string.Empty;
            tab5_txt2.Text = string.Empty;
            tab5_txt3.Text = string.Empty;
            tab5_txt4.Text = string.Empty;
            tab5_txt5.Text = string.Empty;
            tab5_txt6.Text = string.Empty;
            tab5_txt7.Text = string.Empty;
            tab5_txt8.Text = string.Empty;
            this.tabControl1.SelectedIndex = 2;
        }
        /*
         * tab5 screen:
         * in name of project and company just letters and numbers are allowed.
        */
        private void left_btn5_Click(object sender, EventArgs e)
        {
            foreach (char ch in tab5_txt1.Text)
            {
                if (!Char.IsLetterOrDigit(ch))
                {
                    MessageBox.Show("שם פרויקט לא תקין\nשם פרויקט יכול להכיל אותיות ומספרים בלבד וללא רווחים");
                    return;
                }
            }
            if (tab5_txt1.Text == "")
            {
                MessageBox.Show("נא להכניס שם פרויקט .");
                return;
            }
            foreach (char ch in tab5_txt2.Text)
            {
                if (!Char.IsLetterOrDigit(ch))
                {
                    MessageBox.Show("נא להכניס שם חברה מתאים\nשם חברה יכול להכיל אותיות ומספרים בלבד וללא רווחים.");
                    return;
                }
            }
            if (tab5_txt2.Text == "")
            {
                MessageBox.Show("נא להכניס שם חברה מתאים.");
                return;
            }
            int res;
            long res1;
            if (tab5_txt3.Text != string.Empty && long.TryParse(tab5_txt3.Text, out res1) == false)
            {
                MessageBox.Show("נא להכניס מספר טלפון תקין.");
                return;
            }
            if (tab5_txt6.Text != string.Empty && long.TryParse(tab5_txt6.Text, out res1) == false)
            {
                MessageBox.Show("נא להכניס מספר פקס תקין");
                return;
            }
            if (tab5_txt8.Text != string.Empty && (int.TryParse(tab5_txt8.Text, out res) == false || tab5_txt8.Text[0] == '0'))
            {
                MessageBox.Show("נא להכניס מספר עובדים תקין.");
                return;
            }
            if (tab5_txt8.Text == string.Empty)
                res = 0;
            else
                res = int.Parse(tab5_txt8.Text);
            if (res <= 0)
            {
                MessageBox.Show("נא להכניס מספר עובדים תקין.");
                return;
            }
            this.tabControl1.SelectedIndex = 5;
        }

        private void help_btn5_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }
        // 
        // tabPage6
        // 
        private void back_to_menu6_Click(object sender, EventArgs e)
        {
            tab5_txt1.Text = string.Empty;
            tab5_txt2.Text = string.Empty;
            tab5_txt3.Text = string.Empty;
            tab5_txt4.Text = string.Empty;
            tab5_txt5.Text = string.Empty;
            tab5_txt6.Text = string.Empty;
            tab5_txt7.Text = string.Empty;
            tab5_txt8.Text = string.Empty;
            tab6_comboBox1.SelectedIndex = -1;
            tab6_comboBox2.SelectedIndex = -1;
            tab6_comboBox3.SelectedIndex = -1;
            tab6_comboBox4.SelectedIndex = -1;
            this.tabControl1.SelectedIndex = 2;
        }

        private void mid_btn6_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 4;
        }

        private void help_btn6_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }

        private void right_btn6_Click(object sender, EventArgs e)
        {
            int res, indust, subIndust;
            if (tab5_txt8.Text == string.Empty)
                res = 0;
            else
                res = int.Parse(tab5_txt8.Text);

            if (tab6_comboBox1.SelectedItem == null || tab6_comboBox2.SelectedItem == null)
            {
                MessageBox.Show("נא למלא את כל השדות.");
                return;
            }
            IsubIndustryHandler ISH = new subIndustryHandler();
            LinkedList<SubIndustry> sindList = ISH.allSubIndustriesByIndustry((Industry)tab6_comboBox1.SelectedItem);

            if (tab6_comboBox3.SelectedItem == null && sindList.Count > 0)
            {
                MessageBox.Show("נא למלא את כל השדות.");
                return;
            }

            ISubDepartmentHandler ISDH = new SubDepratmentHandler();
            LinkedList<SubDepartment> subdList = ISDH.allSubDeps("SubDepName", true, ((Department)(tab6_comboBox2.SelectedItem)));

            if (tab6_comboBox4.SelectedItem == null && subdList.Count > 0)
            {
                MessageBox.Show("נא למלא את כל השדות.");
                return;
            }
            indust = ((Industry)tab6_comboBox1.SelectedItem).industryNum;
            subIndust = ((SubIndustry)tab6_comboBox3.SelectedItem).subIndustry;
            Project proj = new Project(DateTime.Now, DateTime.Now, tab5_txt1.Text, tab5_txt2.Text, tab5_txt4.Text, tab5_txt6.Text, tab5_txt3.Text, tab5_txt7.Text, tab5_txt5.Text, res, tab5_rich_txt.Text, indust, subIndust);
            projectHandler PH = new projectHandler();
            PH.addProject(proj);
            UserProjectHandler UPH = new UserProjectHandler();
            User user = new User(this.connected_user.Text, "", 0);
            UPH.create(user, proj);
            ProjectDepartmentHandler PDH = new ProjectDepartmentHandler();
            PDH.AddProjectDepartment(proj, (SubDepartment)tab6_comboBox4.SelectedItem);
            this.tabControl1.SelectedIndex = 6;
        }
        // 
        // tabPage7
        // 
        private void back_to_menu7_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 2;
        }

        private void tab7_btn1_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 7;
        }

        private void tab7_btn4_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 9;
        }

        private void tab7_btn2_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 10;
            Project pro = (Project)current_proj.Tag;
            IRolesHandler IRH = new RolesHandler();
            IProjectDepartmentRoles IPDR = new ProjectDepartmentRoles();
            LinkedList<Roles> RolesList = IRH.allRolesGivenProject("roleName", true, pro);
            foreach (Roles role in RolesList)
            {
                LinkedList<int> intervieweeNo = IPDR.allIntervieweeNums("intervieweeNo", true, pro, role);
                foreach (int interviewee in intervieweeNo)
                {
                    interviewsDataGridView.Rows.Add(interviewee, role.roleName, role.intervieweeName);
                }
            }

            //this.objectListView1.
        }

        private void tab7_btn3_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 14;
        }

        private void tab7_btn6_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 17;
        }

        private void help_btn7_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }
        // 
        // tabPage8
        // 
        private void back_to_menu8_Click(object sender, EventArgs e)
        {
            tab8_comboBox1.SelectedIndex = -1;
            tab8_comboBox4.SelectedIndex = -1;
            tab8_comboBox7.SelectedIndex = -1;
            tab8_comboBox3.SelectedIndex = -1;
            tab8_comboBox6.SelectedIndex = -1;
            richTextBox1.Text = "";
            richTextBox2.Text = "";
            this.tabControl1.SelectedIndex = 6;

        }

        private void left_btn8_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 8;
        }

        private void help_btn8_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }
        // 
        // tabPage9
        // 
        private void back_to_menu9_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("חזרה לתפריט ראשי אינה שומרת עדכונים אחרונים.", " האם ברצונך לחזור בכל זאת?", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                tab8_comboBox1.SelectedIndex = -1;
                tab8_comboBox4.SelectedIndex = -1;
                tab8_comboBox7.SelectedIndex = -1;
                tab8_comboBox3.SelectedIndex = -1;
                tab8_comboBox6.SelectedIndex = -1;
                richTextBox1.Text = "";
                richTextBox2.Text = "";
                this.tabControl1.SelectedIndex = 6;
            }
        }

        private void left_btn9_Click(object sender, EventArgs e)
        {
            foreach (DataRow row in ksfProjectTable.Rows)
            {
                KSF ksf = (KSF)row[0];
                ProjectKsf PK = new ProjectKsf();
                PK.addProjectKSF((Project)current_proj.Tag, ksf, int.Parse(row[3].ToString()));
            }

            //IRolesHandler IRH = new RolesHandler();
            //LinkedList<Roles> rolesList = IRH.allRoles("roleName", true); 

            //RolesDatraGridView.DataSource = rolesTable;
            //foreach (Roles role in rolesList)
            //{
            //   CheckBox cb = new CheckBox();
            //   rolesTable.Rows.Add(role, role.roleName, role.roleDesc, role.roleDesc);
            //}
            this.tabControl1.SelectedIndex = 6;
        }

        private void mid_btn9_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 7;
        }

        private void help_btn9_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }
        // 
        // tabPage10
        // 
        private void back_to_menu10_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("חזרה לתפריט ראשי אינה שומרת עדכונים אחרונים.", " האם ברצונך לחזור בכל זאת?", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                RolesDatraGridView.Rows.Clear();
                this.tabControl1.SelectedIndex = 6;
            }
        }

        private void help_btn10_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }
        // 
        // tabPage11
        // 
        private void back_to_menu11_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 6;
        }

        private void help_btn11_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }
        // 
        // tabPage12
        // 
        private void back_to_menu12_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 6;
        }

        private void help_btn12_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }

        private void left_btn12_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 10;
        }

        private void mid_btn12_Click(object sender, EventArgs e)
        {
            Project pro = (Project)current_proj.Tag;
            IQaskedHandler IQH = new qAskedHandler();
            IQAskedCriteriaHandler IQCH = new QAskedCriteriaHandler();
            IInterviewHandler IIH = new InterviewHnadler();
            int intervieweeNo = (int)tabControl1.Tag;
            Interview inter = new Interview(pro.ID, intervieweeNo, "", DateTime.Now, new DateTime());
            IIH.addInterview(inter);
            int i = 0;
            foreach (TreeNode tNode in interviewQue.Nodes)
            {

                if (tNode.Checked == true)
                {

                    foreach (TreeNode tNode1 in tNode.Nodes)
                    {
                        if (tNode1.Checked == true)
                        {
                            i++;
                            Question que = (Question)tNode1.Tag;
                            QAsked queAsked = new QAsked(inter.interviewNo, que.queNo, que.queDesc, que.ksf, i, que.isObs);
                            IQH.AskQuestion(queAsked);
                            foreach (TreeNode tNode2 in tNode1.Nodes)
                            {
                                if (tNode2.Checked == true)
                                {
                                    Criteria cri = (Criteria)tNode2.Tag;
                                    QAskedCriteria qAskedCri = new QAskedCriteria(que.queNo, cri.CriteriaNum, cri.CriteriaDesc);
                                    IQCH.addAskedCriteria(qAskedCri);
                                }


                            }
                        }
                    }
                }

            }
        }
        // 
        // tabPage13
        // 
        private void back_to_menu13_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 6;
        }

        private void help_btn13_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }
        // 
        // tabPage14
        // 
        private void back_to_menu14_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 6;
        }

        private void mid_btn14_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 10;
        }

        private void help_btn14_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }
        // 
        // tabPage15
        // 
        private void back_to_menu15_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 6;
        }

        private void help_btn15_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }
        // 
        // tabPage16
        // 
        private void back_to_menu16_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 6;
        }

        private void left_btn16_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 14;
        }

        private void help_btn16_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }
        // 
        // tabPage17
        // 
        private void back_to_menu17_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 6;
        }

        private void right_btn17_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 15;
        }

        private void help_btn17_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }
        // 
        // tabPage18
        // 
        private void back_to_menu18_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 6;
        }

        private void help_btn18_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }
        // 
        // tabPage19
        // 
        private void back_to_menu19_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 6;
        }

        private void help_btn19_Click(object sender, EventArgs e)
        {
            Help_Form frm = new Help_Form("");
            frm.Show();
        }

        private void tab4_comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {


        }

        private void tab4_comboBox1_DropDown(object sender, EventArgs e)
        {
            tab4_comboBox1.Items.Clear();
            LinkedList<Industry> industryList;
            IIndustryhandler IKH = new IndustryHandler();
            industryList = IKH.allIndustries("industryName", true);
            foreach (Industry indust in industryList)
            {

                tab4_comboBox1.Items.Add(indust);
            }
        }

        private void tab4_comboBox2_DropDown(object sender, EventArgs e)
        {
            tab4_comboBox2.Items.Clear();
            if (tab4_comboBox1.SelectedItem != null)
            {
                IsubIndustryHandler ISH = new subIndustryHandler();
                LinkedList<SubIndustry> sindList = ISH.allSubIndustriesByIndustry((Industry)tab4_comboBox1.SelectedItem);

                foreach (SubIndustry sindust in sindList)
                {
                    tab4_comboBox2.Items.Add(sindust);
                }
            }
            else
            {
                MessageBox.Show("צריך לבחור ענף קודם");
            }
        }
        private void tab4_comboBox4_DropDown(object sender, EventArgs e)
        {
            tab4_comboBox4.Items.Clear();
            LinkedList<Department> depList;
            IDepartmentHandler IDH = new DepartmentHandler();
            depList = IDH.allDeps("DepCode", true);
            foreach (Department dep in depList)
            {

                tab4_comboBox4.Items.Add(dep);
            }
        }

        private void tab4_comboBox6_DropDown(object sender, EventArgs e)
        {
            tab4_comboBox6.Items.Clear();
            if (tab4_comboBox4.SelectedItem != null)
            {
                ISubDepartmentHandler ISH = new SubDepratmentHandler();
                LinkedList<SubDepartment> sdepList = ISH.allSubDeps("SubDepCode", true, (Department)tab4_comboBox4.SelectedItem);

                foreach (SubDepartment sdep in sdepList)
                {
                    tab4_comboBox6.Items.Add(sdep);
                }
            }
            else
            {
                MessageBox.Show("צריך לבחור מחלקה קודם");
            }
        }

        private void tab4_comboBox3_DropDown(object sender, EventArgs e)
        {
            tab4_comboBox3.Items.Clear();
            LinkedList<AnalysisArea> AAList;
            IAnalysisArea IAH = new AnalysisAreaHandler();
            AAList = IAH.allAAs("AreaCode", true);
            foreach (AnalysisArea aa in AAList)
            {

                tab4_comboBox3.Items.Add(aa);
            }
        }

        private void tab4_comboBox5_DropDown(object sender, EventArgs e)
        {
            tab4_comboBox5.Items.Clear();
            if (tab4_comboBox3.SelectedItem != null)
            {
                ISubAnalaysisArea ISH = new SAAHandler();
                LinkedList<SubAnalaysisArea> sAAList = ISH.allSubAnalysisArea("SubAreaCode", true, (AnalysisArea)tab4_comboBox3.SelectedItem);

                foreach (SubAnalaysisArea saa in sAAList)
                {
                    tab4_comboBox5.Items.Add(saa);
                }
            }
            else
            {
                MessageBox.Show("צריך לבחור תחום אבחון קודם");
            }
        }
        private void right_btn13_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 10;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 10;
        }

        private void left_btn14_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 10;
        }

        private void left_btn6_Click(object sender, EventArgs e)
        {

        }

        private void tab10_TLP1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void left_btn18_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 18;
        }

        private void right1_btn19_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 17;
        }

        private void right2_btn19_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 17;
        }

        private void tab10_btn4_Click(object sender, EventArgs e)
        {
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void left_btn12_Click_1(object sender, EventArgs e)
        {
            this.tabControl1.SelectedIndex = 10;
        }

        private void tab6_comboBox1_DropDown(object sender, EventArgs e)
        {
            tab6_comboBox1.Items.Clear();
            tab6_comboBox1.SelectedIndex = -1;
            tab6_comboBox3.SelectedIndex = -1;
            LinkedList<Industry> industryList;
            IIndustryhandler IKH = new IndustryHandler();
            industryList = IKH.allIndustries("industryName", true);
            foreach (Industry indust in industryList)
            {

                tab6_comboBox1.Items.Add(indust);
            }
        }

        private void tab6_comboBox3_DropDown(object sender, EventArgs e)
        {
            tab6_comboBox3.Items.Clear();
            tab6_comboBox3.SelectedIndex = -1;
            if (tab6_comboBox1.SelectedItem != null)
            {
                IsubIndustryHandler ISH = new subIndustryHandler();
                LinkedList<SubIndustry> sindList = ISH.allSubIndustriesByIndustry((Industry)tab6_comboBox1.SelectedItem);

                foreach (SubIndustry sindust in sindList)
                {
                    tab6_comboBox3.Items.Add(sindust);
                }
            }
            else
            {
                MessageBox.Show("צריך לבחור ענף קודם");
            }
        }

        private void tab6_comboBox2_DropDown(object sender, EventArgs e)
        {
            tab6_comboBox2.Items.Clear();
            tab6_comboBox2.SelectedIndex = -1;
            tab6_comboBox4.SelectedIndex = -1;
            LinkedList<Department> DepartmentList;
            IDepartmentHandler IDH = new DepartmentHandler();
            DepartmentList = IDH.allDeps("DepName", true);
            foreach (Department dep in DepartmentList)
            {
                tab6_comboBox2.Items.Add(dep);
            }
        }

        private void tab6_comboBox4_DropDown(object sender, EventArgs e)
        {
            tab6_comboBox4.Items.Clear();
            tab6_comboBox4.SelectedIndex = -1;
            if (tab6_comboBox2.SelectedItem != null)
            {
                ISubDepartmentHandler ISH = new SubDepratmentHandler();
                LinkedList<SubDepartment> sindList = ISH.allSubDeps("SubDepName", true, ((Department)(tab6_comboBox2.SelectedItem)));
                foreach (SubDepartment sindust in sindList)
                {
                    tab6_comboBox4.Items.Add(sindust);
                }
            }
            else
            {
                MessageBox.Show("צריך לבחור מחלקה קודם");
            }
        }

        private void tab8_comboBox1_DropDown(object sender, EventArgs e)
        {
            tab8_comboBox1.Items.Clear();
            LinkedList<Dimension> DimList;
            IDimensionHandler DIMH = new DimensionHandler();
            DimList = DIMH.allDimensions("DimName", true);
            foreach (Dimension dim in DimList)
            {
                tab8_comboBox1.Items.Add(dim);
            }
        }

        private void tab8_comboBox4_DropDown(object sender, EventArgs e)
        {
            tab8_comboBox4.Items.Clear();
            tab8_comboBox7.SelectedIndex = -1;
            LinkedList<AnalysisArea> AnaList;
            IAnalysisArea IAH = new AnalysisAreaHandler();
            AnaList = IAH.allAAs("AreaName", true);
            foreach (AnalysisArea ana in AnaList)
            {
                tab8_comboBox4.Items.Add(ana);
            }
        }

        private void tab8_comboBox7_DropDown(object sender, EventArgs e)
        {
            tab8_comboBox7.Items.Clear();
            if (tab8_comboBox4.SelectedItem != null)
            {
                SAAHandler ISa = new SAAHandler();
                LinkedList<SubAnalaysisArea> sindList = ISa.allSubAnalysisArea("SubAreaName", true);
                foreach (SubAnalaysisArea subana in sindList)
                {
                    tab8_comboBox7.Items.Add(subana);
                }
            }
            else
            {
                MessageBox.Show("נא להכניס תחום קודם.");
                return;
            }
        }

        private void tab8_comboBox3_DropDown(object sender, EventArgs e)
        {
            tab8_comboBox3.Items.Clear();
            LinkedList<KSF> ksfList;
            IKSFHandler IKH = new KSFHandler();
            ksfList = IKH.allKSFs("KSFName", true, (SubAnalaysisArea)tab8_comboBox7.SelectedItem);
            foreach (KSF k in ksfList)
            {
                tab8_comboBox3.Items.Add(k);
            }

        }

        private void tab8_comboBox6_DropDown(object sender, EventArgs e)
        {

        }


        private void tab8_comboBox3_SelectedValueChanged(object sender, EventArgs e)
        {
            richTextBox2.Text = ((KSF)(tab8_comboBox3.SelectedItem)).ksfDiscription;

        }

        private void tab8_btn1_Click(object sender, EventArgs e)
        {
            KSFHandler ksfH = new KSFHandler();

            if (tab8_comboBox3.SelectedItem == null)
            {
                MessageBox.Show("KSF " + "אתה צריך לבחור ");
                return;
            }
            KSF ksf = (KSF)tab8_comboBox3.SelectedItem;
            foreach (DataRow dr in ksfProjectTable.Rows)
            {
                if (((KSF)dr[0]).ksfCode == ksf.ksfCode)
                {
                    MessageBox.Show("זה כבר נבחר " + "KSF");
                    return;
                }

            }
            ksfProjectTable.Rows.Add(ksf, ksf.ksfName, ksf.ksfDiscription);

            dataGridView1.DataSource = ksfProjectTable;


        }

        private void mid_btn4_Click(object sender, EventArgs e)
        {
            if (listView1.Items.Count == 0)
            {
                MessageBox.Show("אין פרויקטים לפתיחה");
                return;
            }
            if (listView1.SelectedItems.Count == 0)
            {
                MessageBox.Show("לא נבחר פרויקט לפתיחה");
                return;
            }
            Project pro = (Project)(listView1.SelectedItems[0].Tag);
            current_proj.Tag = pro;
            current_proj.Text = pro.name;
            tabControl1.SelectedIndex = 6;
            //
            //clearing fields
            //
            tab4_comboBox1.SelectedIndex = -1;
            tab4_comboBox2.SelectedIndex = -1;
            tab4_comboBox3.SelectedIndex = -1;
            tab4_comboBox4.SelectedIndex = -1;
            tab4_comboBox5.SelectedIndex = -1;
            tab4_comboBox6.SelectedIndex = -1;
            listView1.Clear();
        }

        private void left_btn10_Click(object sender, EventArgs e)
        {
            IProjectDepartmentRoles IPDR = new ProjectDepartmentRoles();
            Project pro = (Project)current_proj.Tag;
            IProjectDepartmentHandler IPDH = new ProjectDepartmentHandler();
            SubDepartment projectSD = IPDH.subDepartmentOfGivenProject(pro);
            IRolesHandler IRH = new RolesHandler();

            foreach (DataGridViewRow dr in RolesDatraGridView.Rows)
            {
                if (dr.IsNewRow)
                {
                    return;
                }
                Roles role = new Roles((dr.Cells[0].Value).ToString(), dr.Cells[1].Value.ToString(),
                    dr.Cells[2].Value.ToString(), dr.Cells[3].Value.ToString());
                IRH.addRole(role);
                IPDR.addProjectDepartmentRole(pro, projectSD, role);
                //if ((bool)((DataGridViewCheckBoxCell)dr[0]).TrueValue)
                //{
                //    Roles role = (Roles)dr[0];
                //    IPDR.addProjectDepartmentRole(pro, projectSD, role);
                //}
            }
            tabControl1.SelectedIndex = 6;

        }

        private void interviewsDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            IKSFHandler IKH = new KSFHandler();
            IQuestionHandler IQH = new QuestionHandler();
            ICriteriaHandler ICH = new CriteriaHandler();
            switch (interviewsDataGridView.SelectedCells[0].ColumnIndex)
            {
                case 3:
                    tabControl1.SelectedIndex = 11;
                    interviewQue.Nodes.Clear();
                    tabControl1.Tag = int.Parse(interviewsDataGridView[0, interviewsDataGridView.SelectedCells[0].RowIndex].Value.ToString());
                    LinkedList<KSF> ksfList = IKH.allKSFsGivenProject("KSFCode", true, (Project)current_proj.Tag);
                    int k = 1;
                    foreach (KSF ksf in ksfList)
                    {
                        int q = 1;
                        TreeNode treeN = new TreeNode();
                        treeN.Tag = ksf;
                        treeN.Text = k + "ksf" + ") " + ksf.ksfName;

                        LinkedList<Question> queList = IQH.allQueGivenKSF(ksf, "questionNo", true);
                        foreach (Question que in queList)
                        {
                            int c = 1;
                            TreeNode queTreeNode = new TreeNode();
                            queTreeNode.Tag = que;
                            queTreeNode.Text = "שאלה מס'" + q + ") " + que.queDesc;
                            LinkedList<Criteria> criteriaList = ICH.allCriterias("criteriaNo", true, que);
                            foreach (Criteria cri in criteriaList)
                            {
                                TreeNode criNode = new TreeNode();
                                criNode.Tag = cri;
                                criNode.Text = "קריטריון מס'" + c + ") " + cri.CriteriaDesc;
                                queTreeNode.Nodes.Add(criNode);
                                c++;
                            }

                            treeN.Nodes.Add(queTreeNode);
                            q++;

                        }
                        k++;
                        interviewQue.Nodes.Add(treeN);
                    }

                    break;
                case 4:
                    tabControl1.SelectedIndex = 12;

                    break;
                case 5:
                    tabControl1.SelectedIndex = 13;
                    break;
                default:
                    break;

            }
        }

        private void left_btn13_Click(object sender, EventArgs e)
        {

        }
        private void mid_btn13_Click(object sender, EventArgs e)
        {
            printDialog1.ShowDialog();
        }

        private void interviewQue_DragDrop(object sender, DragEventArgs e)
        {

        }
        private void mid_btn15_Click(object sender, EventArgs e)
        {
            printDialog1.ShowDialog();
        }



        private void mid_btn17_Click(object sender, EventArgs e)
        {
            printDialog1.ShowDialog();
        }

        private void interviewQue_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Move;
        }

        private void interviewQue_AfterSelect(object sender, TreeViewEventArgs e)
        {
        }

        private void interviewQue_AfterCheck(object sender, TreeViewEventArgs e)
        {

        }

        private void interviewQue_BeforeCheck(object sender, TreeViewCancelEventArgs e)
        {

        }






        private void mid_btn19_Click(object sender, EventArgs e)
        {
            printDialog1.ShowDialog();
        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void RolesDatraGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
        //private Rectangle dragBoxFromMouseDown;
        //private int rowIndexFromMouseDown;
        //private int rowIndexOfItemUnderMouseToDrop;
        //private void dataGridView2_DragDrop(object sender, DragEventArgs e)
        //{
        //    // The mouse locations are relative to the screen, so they must be 
        //    // converted to client coordinates.
        //    Point clientPoint = dataGridView2.PointToClient(new Point(e.X, e.Y));

        //    // Get the row index of the item the mouse is below. 
        //    rowIndexOfItemUnderMouseToDrop =
        //    dataGridView2.HitTest(clientPoint.X, clientPoint.Y).RowIndex;

        //    // If the drag operation was a move then remove and insert the row.
        //    if (e.Effect == DragDropEffects.Move)
        //    {
        //        DataGridViewRow rowToMove = e.Data.GetData(
        //                 typeof(DataGridViewRow)) as DataGridViewRow;
        //        dataGridView2.Rows.RemoveAt(rowIndexFromMouseDown);
        //        dataGridView2.Rows.Insert(rowIndexOfItemUnderMouseToDrop, rowToMove);
        //    }
        //}

        //private void dataGridView2_MouseMove(object sender, MouseEventArgs e)
        //{
        //    if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
        //    {
        //        // If the mouse moves outside the rectangle, start the drag.
        //        if (dragBoxFromMouseDown != Rectangle.Empty &&
        //            !dragBoxFromMouseDown.Contains(e.X, e.Y))
        //        {

        //            // Proceed with the drag and drop, passing in the list item.                    
        //            DragDropEffects dropEffect = dataGridView2.DoDragDrop(
        //                dataGridView2.Rows[rowIndexFromMouseDown],
        //                DragDropEffects.Move);
        //        }
        //    }
        //}

        //private void dataGridView2_MouseDown(object sender, MouseEventArgs e)
        //{
        //    // Get the index of the item the mouse is below.
        //    rowIndexFromMouseDown = dataGridView2.HitTest(e.X, e.Y).RowIndex;
        //    if (rowIndexFromMouseDown != -1)
        //    {
        //        // Remember the point where the mouse down occurred. 
        //        // The DragSize indicates the size that the mouse can move 
        //        // before a drag event should be started.                
        //        Size dragSize = SystemInformation.DragSize;

        //        // Create a rectangle using the DragSize, with the mouse position being
        //        // at the center of the rectangle.
        //        dragBoxFromMouseDown = new Rectangle(new Point(e.X - (dragSize.Width / 2),
        //                                                       e.Y - (dragSize.Height / 2)),
        //                                                dragSize);
        //    }
        //    else
        //        // Reset the rectangle if the mouse is not over an item in the ListBox.
        //        dragBoxFromMouseDown = Rectangle.Empty;
        //}

        //private void dataGridView2_DragOver(object sender, DragEventArgs e)
        //{
        //    e.Effect = DragDropEffects.Move;
        //}
    }
}

   
        // 
        // End
        // 
